package com.wcy.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcy.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 吴传亿
 * @since 2025-04-28
 */
public interface UserMapper extends BaseMapper<User> {
    @Results(id="userMap",value = {
            @Result(column = "user_id", property = "userId"),
            @Result(column = "username", property = "username"),
            @Result(column = "password", property = "password"),
            @Result(column = "email", property = "email"),
            @Result(column = "phone", property = "phone"),
            @Result(column = "created_at", property = "createdAt"),
            @Result(column = "updated_at", property = "updatedAt"),
            @Result(column = "last_login", property = "lastLogin"),
            @Result(column = "user_id", property = "roles",many = @Many(select = "com.wcy.mapper.UserRoleMapper.listByUserId"))
    })
    @Select("select * from user where username=#{username}")
    User selectByUsername(String username);

    @ResultMap("userMap")
    @Select("<script>select * from user <where>${ew.sqlSegment}</where></script>")
    Page<User> selectPage(Page<User> page, @Param("ew") Wrapper<User> wrapper);


}

